package middleware

import (
	"goadmin/api"

	"github.com/gin-gonic/gin"
)

type uriPath struct {
	Id uint `uri:"id" binding:"required,gte=1"`
}

func PathId() gin.HandlerFunc {
	return func(c *gin.Context) {
		var path uriPath
		if err := c.ShouldBindUri(&path); err != nil {
			api.Res(c, api.CodeInvalidUrl, "invalid id")
			c.Abort()
			return
		}
		c.Set("path_id", uint(path.Id))
		c.Next()
	}
}
